package com.social.servlet;

import com.social.dao.LogDAO;
import com.social.model.Log;
import com.social.model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/publishLog")
public class PublishLogServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        int userId = ((User) session.getAttribute("user")).getId();
        String content = request.getParameter("content");
        String attachment = request.getParameter("attachment");
        String link = request.getParameter("link");
        String location = request.getParameter("location");
        String scope = request.getParameter("scope");

        Log log = new Log();
        log.setUserId(userId);
        log.setContent(content);
        log.setAttachment(attachment);
        log.setLink(link);
        log.setLocation(location);
        log.setScope(scope);

        LogDAO logDAO = new LogDAO();
        logDAO.publishLog(log);
        response.sendRedirect("socialCircle.jsp");
    }
    @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.sendRedirect("socialCircle.jsp"); // 重定向到添加好友的页面
}
}